package wowmobile;

import java.util.ArrayList;
import java.util.List;

public class Party {

    //#0 is party lider
    private List<Player> partyList;

    Party()
    {
        partyList = new ArrayList<Player>();
    }
    Party(Player owner, Player player)
    {
        System.out.println(owner.getStats().getNick()+" "+player.getStats().getNick());
        partyList = new ArrayList<Player>();
        partyList.add(owner);
        partyList.add(player);
    }

    public String addToParty(Player adder, Player player) {
        if (partyList.indexOf(adder) == 0) {
            if (partyList.size() >= 6) {
                return "Party is full.";
            } else {
                partyList.add(player);
                return "Ok.";
                //referencja do listy playerów, dobranie się do nicka i zamiast ok, wpisanie nicka i "... added to party."?
            }
        } else {
            return "You are not party leader.";
        }
    }

    public String removeFromParty(Player adder, Player player) {
        if (partyList.indexOf(adder) == 0) {
            if (partyList.indexOf(player) == 0 && partyList.size() > 1) {
                String newleader = promote(adder, partyList.get(1));
                return "Player removed" + " and " + newleader;
            } else {
                partyList.remove(partyList.indexOf(player));
                //referencja do listy playerów, dobranie się do nicka i zamiast ok, wpisanie nicka i "... has been removed."?
                return "Player removed.";
            }
        } else {
            return "You are not party leader.";
        }
    }

    public String disband(Player adder) {
        if (partyList.indexOf(adder) == 0) {
            partyList.removeAll(partyList);
            return "Party has been disbanded.";
        } else {
            return "You are not party leader.";
        }
    }

    public String promote(Player adder, Player newowner) {
        if (partyList.indexOf(adder) == 0) {
            List<Player> robpartyList = new ArrayList<Player>();
            robpartyList.add(newowner);
            partyList.remove(partyList.indexOf(newowner));
            while (partyList.size() > 0) {
                robpartyList.add(partyList.remove(0));
            }
            partyList = new ArrayList<Player>(robpartyList);
            //string który ma nazwę player "... is new leader."?
            return "New leader setted.";
        } else {
            return "You are not party leader.";
        }
    }

    public boolean isLeader(Player playerId) {
        if (partyList.indexOf(playerId) == 0) {
            return true;
        } else {
            return false;
        }
    }

    public Player whoisLeader() {
        return partyList.get(0);
    }

    public List<Player> getPartyList() {
        return partyList;
    }

    public void setPartyList(List<Player> partyList) {
        this.partyList = partyList;
    }


}
